public class SrVsSB {

    //思路：比较运行时间

    public static void main(String[] args) {
        int n = 10000;
        long stratTime, endTime;

        //String 追加
        stratTime = System.currentTimeMillis();
        String str = "";
        for(int i = 0;i < n;i++)
            str += 'A';
        endTime = System.currentTimeMillis();
        long stringTime = stratTime - endTime;

        //stringBuffer 追加
        stratTime = System.currentTimeMillis();
        StringBuffer sb = new StringBuffer();
        for(int i = 0;i < n;i++)
            sb.append('A');
        endTime = System.currentTimeMillis();
        long stringbufferTime = endTime - stratTime;

        System.out.println("String追加运行时间:" + stringTime + "毫秒");
        System.out.println("StringBuffer追加运行时间:" + stringbufferTime + "毫秒");
        String winner = stringTime > stringbufferTime ? "StringBuffer" : "String";
        System.out.println("所以" + winner + "的效率更高");
    }
}
